package com.yan_jiu_sheng.LeetCodeHot100.AC;

import java.util.Stack;

/**
 * https://leetcode.cn/problems/min-stack/description/?envType=study-plan-v2&envId=top-100-liked
 * AC 通过
 *
 * @author yulongTian
 * @create 2024-07-10 17:02
 */
public class Test68 {
    public static void main(String[] args) {

    }

    class MinStack {

        Stack<Integer> numStack;
        Stack<Integer> minStack;

        public MinStack() {
            this.numStack = new Stack<>();
            this.minStack = new Stack<>();
        }

        public void push(int val) {
            numStack.push(val);
            if (minStack.empty()) {
                minStack.push(val);
            } else {
                minStack.push(Math.min(val, minStack.peek()));
            }
        }

        public void pop() {
            numStack.pop();
            minStack.pop();
        }

        public int top() {
            return numStack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
    }

}
